package com.tingyukeji.fastpay.utils;

import android.text.TextUtils;

import java.util.Date;

/**
 * Created by Administrator on 2016/12/5.
 */

public class TimeUtils {
    public static String getDValue(long stime, long betweenTime) {
        StringBuffer buffer = new StringBuffer();
        Date now = new Date();
        long l = now.getTime() - stime + betweenTime;
        if (l < 0) {
            return "00:00:00";
        }
        long day = l / (24 * 60 * 60 * 1000);
        long hour = (l / (60 * 60 * 1000) - day * 24);
        long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);
        long s = (l / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
        if (hour > 0) {
            if (String.valueOf(hour).length() == 1) {
                buffer.append("0");
            }
            buffer.append(hour);
        } else {
            buffer.append("00");
        }
        buffer.append(":");
        if (min > 0) {
            if (String.valueOf(min).length() == 1) {
                buffer.append("0");
            }
            buffer.append(min);
        } else {
            buffer.append("00");
        }
        buffer.append(":");
        if (s > 0) {
            if (String.valueOf(s).length() == 1) {
                buffer.append("0");
            }
            buffer.append(s);
        } else {
            buffer.append("00");
        }
        return buffer.toString();
    }

    public static long getStopTime(String stime) {
        String hour = stime.split(":")[0];
        String min = stime.split(":")[1];
        String s = stime.split(":")[2];
        if (!TextUtils.isEmpty(hour)){
            if ("0".equals(hour.substring(0,1))){
                hour = hour.substring(1);
            }
        }
        if (!TextUtils.isEmpty(min)){
            if ("0".equals(min.substring(0,1))){
                min = min.substring(1);
            }
        }
        if (!TextUtils.isEmpty(s)){
            if ("0".equals(s.substring(0,1))){
                s = s.substring(1);
            }
        }
        return Integer.parseInt(hour)*60*60*1000 + Integer.parseInt(min)*60*1000 + Integer.parseInt(s)*1000;
    }
}
